package com.test.pack1.demo;

import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;

/**
 * Created by dws on 2017/11/7.
 * 定容栈
 */
public class Demo1 {

    public class FixedCapacityStackOfStrings{
        private String[] a;
        private int N;

        public FixedCapacityStackOfStrings(int cap) {
            a =  new String[cap];
        }
        public boolean isEmpty(){
            return N==0;
        }
        public int size(){return N;}

        public void push(String item){
            a[N++]=item;
        }

        public String pop(){return a[--N];}
    }


    public static void main(String[] args) {
        Demo1 dome1 = new Demo1();
        FixedCapacityStackOfStrings s = dome1.new FixedCapacityStackOfStrings(100);
        while(!StdIn.isEmpty()){
            String item = StdIn.readString();
            if(!item.equals("-")){
                s.push(item);
            }
            else if(!s.isEmpty()){
                StdOut.print(s.pop()+" ");
            }
            StdOut.println("("+s.size()+" left on stack)");
        }
    }


}
